#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Import('env')
import os
import os.path
unittests_env = env.Clone()

src_dir = unittests_env.get('SRC_DIR')
pi_dir = os.path.join(src_dir, 'plugins')
build_dir = env.get('BUILD_DIR')
######################################################################
# Build flags
######################################################################
unittests_env.PrependUnique(CPPPATH = [
                os.path.join(pi_dir, 'include'),
                '#extlibs/gtest/gtest-1.7.0/include',
		])

unittests_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
unittests_env.PrependUnique(LIBS = ['-lpthread'])
unittests_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
unittests_env.AppendUnique(LIBPATH = [os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0', 'lib', '.libs')])
unittests_env.PrependUnique(LIBS = [
		'plugin_interface',
		'oc',
		'octbstack',
		'oc_logger',
		'connectivity_abstraction',
		'coap',
		'gtest',
		'gtest_main'
		])

if env.get('LOGGING'):
	unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])

######################################################################
# Source files and Targets
######################################################################
piunittests = unittests_env.Program('piunittests', ['plugininterfacetest.cpp'])

Alias("piunittests", [piunittests])

env.AppendTarget('piunittests')
if env.get('TEST') == '1':
	target_os = env.get('TARGET_OS')
	if target_os == 'linux':
                from tools.scons.RunTest import *
                run_test(unittests_env,
                         'plugins_unittests.memcheck',
                         'plugins/unittests/piunittests')

